package com.zhaotianhao.util;

import com.github.pagehelper.PageInfo;
import com.zhaotianhao.pojo.Goods;
import com.zhaotianhao.service.GoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author Z-7
 * @Date 2022/3/8
 */
@Component
@EnableScheduling
public class GoodsTask {
    @Autowired
    private GoodsRepository goodsRepository;
    @DubboReference
    private GoodsService goodsService;

    @Scheduled(cron = "0 0 * * * ?")
    public void esAll(){
        goodsRepository.deleteAll();
        PageInfo<Goods> page = goodsService.queryByPage(null, 1, 100);
        goodsRepository.saveAll(page.getList());
    }
}
